/**
 * Copyright (c) 2012, SHX Studio.
 * All rights reserved.
 * rosary226@gmail.com
 * 
 * @author shenqianfeng
 * @date 2012-9-1  
 * @version 1.0   
 */


package com.xxx.sqfengine;

import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class SQFGLActivity extends Activity implements SQFGLSceneController{
	protected SQFGLSurfaceView mGLSurfaceView;
	protected SQFGLRenderer mRenderer;
	
	protected SQFGLScene mScene;
	
	private Handler mInitHandler = new Handler();
	private Handler mUpdateHandler = new Handler();
	private Runnable mInitRunnable = new Runnable() {
		public void run() {
			initScene();
		}
	};
	
	private Runnable mUpdateRunnable = new Runnable() {
		public void run() {
			updateScene();
		}
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		// set to fullscreen
		this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        // initialize the SQFGLEnvironment...It's important!
        SQFGLEnvironment.init(this.getApplicationContext());
		
		mGLSurfaceView = new SQFGLSurfaceView(this);
		mScene = new SQFGLScene(this);
		mRenderer = new SQFGLRenderer(mScene);
		mGLSurfaceView.setRenderer(mRenderer);
		
		
		//mGLSurfaceView.setRenderMode(GL10.GL)
		
		this.setContentView(mGLSurfaceView);
	}
	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event) {

/*		if(keyCode == KeyEvent.ACTION_UP) {
			finish();
			return false;
		}*/
		return super.onKeyUp(keyCode, event);
	}
	
	public void initScene() {
		Log.i("SQFGL", "init scene");
		System.out.println("init scene");
	}
	
	public void updateScene() {
		Log.i("SQFGL", "update scene");
		System.out.println("update scene");
	}
	
	public Handler getInitHandler() {
		return mInitHandler;
	}
	
	public Handler getUpdateHandler() {
		return mUpdateHandler;
	}
	
	public Runnable getInitRunnable() {
		return mInitRunnable;
	}
	
	public Runnable getUpdateRunnable() {
		return mUpdateRunnable;
	}
}
